<?php 
    class UserControllers extends Controllers
    {
        private $model;
        public function __construct()
        {
            parent::__construct();
            $this->model = new Model("user");
        }
        public function index()
        {
            $list = $this->model->order('id desc')->select();
            $this->assign("title","用户列表");
            $this->assign("list",$list);
            $this->display("./user/index.html");
        }
         /**
          * [add 跳转到添加页面]
          */
         public function add()
        {
            $this->assign("title","添加用户");
            $this->display("./user/add.html");
        }

        /**
         * [del 删除数据]
         */
        public function del()
        {
            if($this->model->delete($_GET['id'])) {
                $this->redirect("恭喜您删除成功","./index.php?c=User");
            } else {
                $this->redirect("恭喜您删除失败","./index.php?c=user");
            }             
        }

        /**
         * [insert 执行添加数据]
         */
        public function insert()
        {
            if ($this->model->insert() > 0) {
                $this->redirect("恭喜您添加成功","./index.php?c=User");
            } else {
                $this->redirect("恭喜您添加失败");
            }
        }

        /**
         * [edit 跳转到编辑模板]
         */
        public function edit()
        {
            $list = $this->model->find($_GET['id']);
            $this->assign("title","修改用户");
            $this->assign("list",$list);
            $this->display("./user/edit.html");
        }

        /**
         * [update 执行修改函数]
         */
        public function update()
        {
          if ($list = $this->model->update()) {
                $this->redirect("恭喜您修改成功","./index.php?c=User");
            } else {
                $this->redirect("恭喜您修改失败");
            }
        }
    }





